package com.api.browser.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.api.browser.service.BrowserService;

import weaver.conn.RecordSet;
import weaver.general.Util;

/**
 * 岗位查询
 * INSERT INTO wf_browser_config (type, clazz, description, linkurl, titelebel, icon, iconColor, iconBgcolor, mobileLinkUrl) VALUES 
 * ('289', 'com.api.browser.service.impl.GetUserInfoService', '', '', NULL, NULL, NULL, NULL, NULL) 
 * 拷贝 class 到 %weaver%\ecology\classbean\com\api\browser\service\impl
 */
public class GetUserInfoService extends BrowserService {
	
	@Override
	@SuppressWarnings("deprecation")
	public Map<String, Object> getBrowserData(Map<String, Object> paramMap) throws Exception {
		HashMap<String, Object> hashMap = new HashMap<>();
		String loginid = Util.null2String(paramMap.get("loginid"));
		//
		HashMap<Object, Object> dataMap = new HashMap<>();
		if (loginid != null && !loginid.isEmpty()) {
			String sql = "select r.id, r.lastname, r.workcode, r.subcompanyid1, r.departmentid, r.jobtitle, j.jobactivityid"
					+ " from HrmResource r inner join HrmJobTitles j on r.jobtitle = j.id where loginid = '%s'";
			sql = String.format(sql, loginid);
			//
			RecordSet recordSet = new RecordSet();
			recordSet.executeSql(sql);
			if (recordSet.next()) {
				dataMap.put("id", recordSet.getInt("id"));
				dataMap.put("lastname", recordSet.getString("lastname"));
				dataMap.put("workcode", recordSet.getString("workcode"));
				dataMap.put("subcompanyid", recordSet.getInt("subcompanyid1"));
				dataMap.put("departmentid", recordSet.getInt("departmentid"));
				dataMap.put("jobtitle", recordSet.getInt("jobtitle"));
				dataMap.put("jobactivityid", recordSet.getInt("jobactivityid"));
			}
		}
		// 返回
		ArrayList<HashMap<Object, Object>> datalList = new ArrayList<>();
		if (dataMap.size() > 0) {
			datalList.add(dataMap);
		}
		hashMap.put("datas", datalList);
		return hashMap;
	}
	
	@Override
	@SuppressWarnings("deprecation")
	public Map<String, Object> browserAutoComplete(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse) throws Exception {
		HashMap<String, Object> hashMap = new HashMap<>();
		String loginid = Util.null2String(paramHttpServletRequest.getParameter("loginid"));
		//
		HashMap<Object, Object> dataMap = new HashMap<>();
		if (loginid != null && !loginid.isEmpty()) {
			String sql = "select r.id, r.lastname, r.workcode, r.subcompanyid1, r.departmentid, r.jobtitle, j.jobactivityid"
					+ " from HrmResource r inner join HrmJobTitles j on r.jobtitle = j.id where loginid = '%s'";
			sql = String.format(sql, loginid);
			//
			RecordSet recordSet = new RecordSet();
			recordSet.executeSql(sql);
			if (recordSet.next()) {
				dataMap.put("id", recordSet.getInt("id"));
				dataMap.put("lastname", recordSet.getString("lastname"));
				dataMap.put("workcode", recordSet.getString("workcode"));
				dataMap.put("subcompanyid", recordSet.getInt("subcompanyid1"));
				dataMap.put("departmentid", recordSet.getInt("departmentid"));
				dataMap.put("jobtitle", recordSet.getInt("jobtitle"));
				dataMap.put("jobactivityid", recordSet.getInt("jobactivityid"));
			}
		}
		// 返回
		ArrayList<HashMap<Object, Object>> datalList = new ArrayList<>();
		if (dataMap.size() > 0) {
			datalList.add(dataMap);
		}
		hashMap.put("datas", datalList);
		return hashMap;
		
	}
}

